package com.weaver.teams;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MyProxy {

    public Object invoke(Object o, Method method, Object[] args) {
        try {
            System.out.println("开始");
            Object invoke = method.invoke(o, args);
            System.out.println("结束");
            return invoke;
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        try {
            MyProxy myProxy = new MyProxy();
            String s = "2266666";
            Method length = String.class.getMethod("length");
            Object invoke = myProxy.invoke(s, length, null);
            System.out.println(invoke);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }
}
